<template>
  <div>
    <el-dialog :visible.sync="show" width="80%" title="新增波形调试工单" @close="closeDialog">
      <el-tabs v-model="activeName" type="card" @tab-click="handleClick">
        <el-tab-pane label="基础信息" name="first">
          <el-form :inline="true" :model="form" :rules="rules" label-width="120px">
            <el-row :gutter="20">
              <el-col :span="8">
                <el-form-item label="工单号">
                  <el-input v-model="form.fOrderNo" disabled></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="MES 工单号">
                  <div style="display: flex;gap: 12px;">
                    <el-input v-model="form.fMesNo" :disabled="form.fIsMes"></el-input>
                    <el-checkbox label="不绑定工单号" v-model="form.fIsMes" @change="handleCheckboxChange"></el-checkbox>
                  </div>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="工单优先级" prop="fOrderPriority">
                  <el-select v-model="form.fOrderPriority" placeholder="请选择">
                    <el-option label="紧急" value="0"></el-option>
                    <el-option label="高" value="1"></el-option>
                    <el-option label="中" value="2"></el-option>
                    <el-option label="低" value="3"></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="8">
                <el-form-item label="工单名称">
                  <el-input v-model="form.fOrderName"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="所属工厂" prop="fOrgId">
                  <el-select v-loadmore="factoryLoad" v-model="form.fOrgId" placeholder="请选择" @change="changeFactory">
                    <el-option v-for="(item, index) in factoryList" :key="index" :label="item.fOrgName"
                      :value="item.fId"></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="所属设备" prop="fDeviceId">
                  <el-select v-loadmore="deviceLoad" v-model="form.fDeviceId" placeholder="请选择">
                    <el-option v-for="(item, index) in deviceList" :key="index" :label="item.fDeviceName"
                      :value="item.fId"></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="8">
                <el-form-item label="客户" prop="fClientName">
                  <el-select v-loadmore="clientLoad" v-model="form.fClientName" placeholder="请选择">
                    <el-option v-for="(item, index) in clientList" :key="index" :label="item.fClientCode"
                      :value="item.fId"></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="负责人" prop="fUserId">
                  <el-select v-loadmore="userLoad" v-model="form.fUserId" placeholder="请选择">
                    <el-option v-for="(item, index) in userList" :key="index" :label="item.nickName"
                      :value="item.userId"></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="产品" prop="fProductId">
                  <div @click="openProduct" class="el-input-div">{{ product.fProductName }}</div>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="8">
                <el-form-item label="模组类型">
                  <el-input :value="product.wfModuleColor ? product.wfModuleColor.fModuleName : ''" disabled></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="尺寸">
                  <el-input v-model="product.fProductSize" disabled></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="产品型号">
                  <el-input v-model="product.fDeviceModel" disabled></el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="8">
                <el-form-item label="产品批次" prop="fProductBatchNo">
                  <el-select v-model="form.fProductBatchNo" placeholder="请选择">
                    <el-option v-for="(item, index) in batchList" :key="index" :label="item.fBatchNo"
                      :value="item.fEntryId"></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="托盘规格" prop="fTraySpecofocatopns">
                  <el-select v-model="form.fTraySpecofocatopns" placeholder="请选择">
                    <el-option label="6片" value="6片"></el-option>
                    <el-option label="5片" value="5片"></el-option>
                    <el-option label="4片" value="4片"></el-option>
                    <el-option label="3片" value="3片"></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="交付日期" prop="fPayDate">
                  <el-date-picker v-model="form.fPayDate" type="date" value-format="yyyy-MM-dd"
                    placeholder="选择日期"></el-date-picker>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="8">
                <el-form-item label="VCOM 值" prop="fVcom">
                  <el-input v-model.number="form.fVcom" type="number" clearable placeholder="请输入 VCOM 值"
                    @input="handleInputw"></el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="24">
                <el-form-item label="备注">
                  <el-input type="textarea" :rows="4" placeholder="请输入内容" v-model="form.fRemark"
                    style="max-width: 1200px;"></el-input>
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
        </el-tab-pane>
        <el-tab-pane label="VS 值设置" name="second">
          <div class="flex">
            <div class="w-20" style="font-size: 16px;font-weight: 600;">VS_W 数值设置</div>
            <div
              style="vertical-align: middle;text-align: right;display: inline-block;width: 100%;border-top: 1px solid #ccc;margin-top:10px">
            </div>
          </div>
          <br>
          <div>
            <el-form ref="form" :model="form" :rules="rules" label-width="150px">
              <el-row>
                <el-col :span="20">
                  <el-form-item label="VS_W 数值使用开关" prop="fVsWSetting">
                    <el-switch v-model="form.fVsWSetting" :active-value="1" :inactive-value="0" active-color="#13ce66"
                      inactive-color="#ff4949" @change="toggleFormVisibility"></el-switch>
                  </el-form-item>
                </el-col>
              </el-row>
            </el-form>
            <br>
            <el-row :gutter="10" class="mb8">
              <el-col :span="1.5">
                <el-button type="primary" icon="el-icon-plus" size="mini" @click="handleAddWfPlanDetail"
                  v-if="form.fVsWSetting">添加</el-button>
              </el-col>
            </el-row>
            <el-table style="width:100%;" :data="wfPlanDetailList" :row-class-name="rowWfPlanDetailIndex"
              @selection-change="handleWfPlanDetailSelectionChange" ref="wfPlanDetail" v-if="form.fVsWSetting">
              <el-table-column type="selection" width="150" align="center" />
              <el-table-column label="序号" align="center" prop="index" width="100" />
              <el-table-column label="温度段" width="120" align="center">
                <template slot-scope="scope">
                  <el-input v-model.number="scope.row.fHeatStage" type="number" placeholder="请输入" clearable
                    style="width: 100px" />
                </template>
              </el-table-column>
              <el-table-column label="VS_W 数值" width="120" align="center">
                <template slot-scope="scope">
                  <el-input v-model.number="scope.row.fVs" type="number" placeholder="请输入 VS_W 数值" clearable
                    style="width: 100px" @input="handleInput(scope.row)" />
                </template>
              </el-table-column>
              <el-table-column label="操作" align="center" prop="fRemark" width="200">
                <template slot-scope="scope">
                  <el-button type="danger" icon="el-icon-delete" size="mini"
                    @click="handleDeleteWfPlanDetail(scope.$index)">删除</el-button>
                </template>
              </el-table-column>
            </el-table>
          </div>
          <div class="flex">
            <div class="w-20" style="font-size: 16px;font-weight: 600;">VS_R 数值设置</div>
            <div
              style="vertical-align: middle;text-align: right;display: inline-block;width: 100%;border-top: 1px solid #ccc;margin-top:10px">
            </div>
          </div>
          <br>
          <div>
            <el-form ref="form" :model="form" :rules="rules" label-width="150px">
              <el-row>
                <el-col :span="20">
                  <el-form-item label="VS_R 数值使用开关" prop="fVsRSetting">
                    <el-switch v-model="form.fVsRSetting" :active-value="1" :inactive-value="0" active-color="#13ce66"
                      inactive-color="#ff4949" @change="toggleFormVisibilitys"></el-switch>
                  </el-form-item>
                </el-col>
              </el-row>
            </el-form>
            <br>
            <el-row :gutter="10" class="mb8">
              <el-col :span="1.5">
                <el-button type="primary" icon="el-icon-plus" size="mini" @click="handleAddWfPlanDetails"
                  v-if="form.fVsRSetting">添加</el-button>
              </el-col>
            </el-row>
            <el-table style="width:100%;" :data="wfPlanDetailLists" :row-class-name="rowWfPlanDetailIndex"
              @selection-change="handleWfPlanDetailSelectionChanges" ref="wfPlanDetail" v-if="form.fVsRSetting">
              <el-table-column type="selection" width="150" align="center" />
              <el-table-column label="序号" align="center" prop="index" width="100" />
              <el-table-column label="温度段" width="120" align="center">
                <template slot-scope="scope">
                  <el-input v-model.number="scope.row.fHeatStage" type="number" placeholder="请输入" clearable
                    style="width: 100px" />
                </template>
              </el-table-column>
              <el-table-column label="VS_R 数值" width="120" align="center">
                <template slot-scope="scope">
                  <el-input v-model.number="scope.row.fVs" type="number" placeholder="请输入" clearable
                    style="width: 100px" @input="handleInputs(scope.row)" />
                </template>
              </el-table-column>
              <el-table-column label="操作" align="center" prop="fRemark" width="200">
                <template slot-scope="scope">
                  <el-button type="danger" icon="el-icon-delete" size="mini"
                    @click="handleDeleteWfPlanDetails(scope.$index)">删除</el-button>
                </template>
              </el-table-column>
            </el-table>
          </div>
        </el-tab-pane>
        <el-tab-pane label="任务设置" name="third">
          <el-dropdown>
            <el-button size="mini" type="primary">
              新增<i class="el-icon-arrow-down el-icon--right"></i>
            </el-button>
            <el-dropdown-menu slot="dropdown">
              <el-button type="text" @click="addSession(1)"
                style="font-size:  12px; padding: 8px 10px;">预调试VS_R任务</el-button><br>
              <el-button type="text" @click="addSession(2)"
                style="font-size: 12px; padding: 8px 10px;">预调试VS_W任务</el-button><br>
              <el-button type="text" @click="showBialog2(3)"
                style="font-size: 12px; padding: 8px 10px;">LAB值调试任务</el-button><br>
              <el-button type="text" @click="showBialog2(4)"
                style="font-size: 12px; padding: 8px 10px;">动态类型调试任务</el-button><br>
            </el-dropdown-menu>
          </el-dropdown>
          <el-form><br>
            <el-form-item prop="configKey">
              <el-table :data="form.wfOrderTaskList" @selection-change="handleSelectionChange">
                <el-table-column label="编号" type="index" width="120" />
                <el-table-column label="任务名称" prop="fTaskName" :show-overflow-tooltip="true" align="center"
                  min-width="200" />
                <el-table-column label="调试任务类型" prop="fTaskType" :show-overflow-tooltip="true" align="center"
                  min-width="200">
                  <template slot-scope="scope">
                    <span>{{
                      scope.row.fTaskType === 0 ? '质检任务'
                        : scope.row.fTaskType === 1 ? '预调试VS_R任务'
                          : scope.row.fTaskType === 2 ? '预调试VS_W任务'
                            : scope.row.fTaskType === 3 ? 'LAB值调试任务'
                              : scope.row.fTaskType === 4 ? '动态波形调试任务'
                                : '' }}</span>
                  </template>
                </el-table-column>
                <el-table-column label="温度段" prop="fHeatStageCollection" :show-overflow-tooltip="true" align="center"
                  min-width="200" />
                <el-table-column label="期待LAB范围值" align="center">
                  <el-table-column label="B" min-width="100">
                    <template slot-scope="scope">
                      <div>{{
                        scope.row.bcmClientPreset ? 'L:' + scope.row.bcmClientPreset.fBlackLMin + '-' +
                          scope.row.bcmClientPreset.fBlackLMin + ',' + 'A:' + scope.row.bcmClientPreset.fBlackAMin + '-' +
                          scope.row.bcmClientPreset.fBlackAMax + ',' + 'B:' + scope.row.bcmClientPreset.fBlackBMin + '-' +
                          scope.row.bcmClientPreset.fBlackBMax : ''
                      }}</div>
                    </template>
                  </el-table-column>
                  <el-table-column label="W" min-width="100">
                    <template slot-scope="scope">
                      <div>{{
                        scope.row.bcmClientPreset ? 'L:' + scope.row.bcmClientPreset.fWhiteLMin + '-' +
                          scope.row.bcmClientPreset.fWhiteLMin + ',' + 'A:' + scope.row.bcmClientPreset.fWhiteAMin + '-' +
                          scope.row.bcmClientPreset.fWhiteAMax + ',' + 'B:' + scope.row.bcmClientPreset.fWhiteBMin + '-' +
                          scope.row.bcmClientPreset.fWhiteBMax : ''
                      }}</div>
                    </template>
                  </el-table-column>
                  <el-table-column label="R" min-width="100">
                    <template slot-scope="scope">
                      <div>{{
                        scope.row.bcmClientPreset ? 'L:' + scope.row.bcmClientPreset.fRedLMin + '-' +
                          scope.row.bcmClientPreset.fRedLMin + ',' + 'A:' + scope.row.bcmClientPreset.fRedAMin + '-' +
                          scope.row.bcmClientPreset.fRedAMax + ',' + 'B:' + scope.row.bcmClientPreset.fRedBMin + '-' +
                          scope.row.bcmClientPreset.fRedBMax : ''
                      }}</div>
                    </template>
                  </el-table-column>
                  <el-table-column label="Y" min-width="100">
                    <template slot-scope="scope">
                      <div>{{
                        scope.row.bcmClientPreset ? 'L:' + scope.row.bcmClientPreset.fYellowLMin + '-' +
                          scope.row.bcmClientPreset.fYellowLMin + ',' + 'A:' + scope.row.bcmClientPreset.fYellowAMin + '-'
                          +
                          scope.row.bcmClientPreset.fYellowAMax + ',' + 'B:' + scope.row.bcmClientPreset.fYellowBMin + '-'
                          +
                          scope.row.bcmClientPreset.fYellowBMax : ''
                      }}</div>
                    </template>
                  </el-table-column>
                </el-table-column>
                <el-table-column label="温箱总静置时间(分钟)" prop="fQuietMinuteCollection" :show-overflow-tooltip="true"
                  align="center" min-width="200" />
                <el-table-column label="测试总托盘数" prop="fTextNumCollection" :show-overflow-tooltip="true" align="center"
                  min-width="200">
                  <template slot-scope="scope">
                    <div>{{ formatTextNumCollection(scope.row) }}</div>
                  </template>
                </el-table-column>
                <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
                  <template slot-scope="scope" v-if="scope.row.roleId !== 1">
                    <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
                      v-hasPermi="['system:product:edit']">编辑</el-button>
                    <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
                      v-hasPermi="['system:product:remove']">删除</el-button>
                  </template>
                </el-table-column>
              </el-table>
            </el-form-item>
          </el-form>
        </el-tab-pane>
      </el-tabs>
      <div slot="footer" class="dialog-footer">
        <el-button @click="show = false; refreshPage()">取 消</el-button>
        <el-button type="primary" @click="toSure">确 定</el-button>
      </div>
    </el-dialog>
    <Product ref="product" @sure="sureProduct"></Product>
    <!-- <LABvalue ref="LABvalue" @sure="sureProduct"></LABvalue> -->
    <TaskAdds ref="taskAdds" @sure="sureTask"></TaskAdds>
    <Boxing ref="boxing" @sure="sureTaskw" ></Boxing>
  </div>
</template>

<script>
import { listOrg } from "@/api/basicData/factory"
import { listDevice } from "@/api/basicData/equipment"
import { listClient } from "@/api/basicData/customer"
import { listUser } from "@/api/system/user"
import { productNo, addOrder } from '@/api/workOrder/administration'
import Lab from './components/boxing.vue'
import Product from "./components/product.vue"
import TaskAdds from "./components/taskAdds.vue"
import Boxing from "./components/boxing.vue"
// import LABvalue from "./componentst/LABvalue.vue"

export default {
  name: "workOrder",
  components: {
    Product,
    Lab,
    TaskAdds,
    Boxing,
    // LABvalue,
  },
  data() {
    return {
      show: false,
      activeName: 'first',
      checkedWfPlanDetail: [],
      checkedWfPlanDetails: [],
      // 岗位表格数据
      postList: [],
      inputs: '',
      dialoge1: false,
      dialoge2: false,
      dialoge3: false,
      dialoge4: false,
      fVsWSetting: [
        { value: 0, label: '启用' },
        { value: 1, label: '停用' }
      ],
      fVsRSetting: [
        { value: 0, label: '启用' },
        { value: 1, label: '停用' }
      ],
      form: {
        fVsWSetting: 0,
        fVsRSetting: 0,
        fLogicalSettings: 0,
        fOrderNo: '',
        fMesNo: '',
        fIsMes: false,
        fOrderPriority: '',
        fOrderName: '',
        fOrgId: '',
        fDeviceId: '',
        fClientName: '',
        fUserId: '',
        fProductId: '',
        fProductBatchNo: '',
        fTraySpecofocatopns: '',
        fPayDate: '',
        inputs: '',
        fRemark: '',
        fOrderType: 1,
        wfOrderTaskList: [],
        // wfPlanDetailList: [],
        // wfPlanDetailLists: [],
        check: 0,
        // wfVsSettingList: []
      },
      wfPlanDetailList: [],
      wfPlanDetailLists: [],
      wfVsSettingList: [],
      rules: {
        fOrderName: [{ required: true, message: '请填写工单名称', trigger: 'blur' }],
        fOrderPriority: [{ required: true, message: '请选择工单优先级', trigger: 'blur' }],
        fOrgId: [{ required: true, message: '请选择所属工厂', trigger: 'blur' }],
        fDeviceId: [{ required: true, message: '请选择所属设备', trigger: 'blur' }],
        fClientName: [{ required: true, message: '请选择客户', trigger: 'blur' }],
        fUserId: [{ required: true, message: '请选择负责人', trigger: 'blur' }],
        fProductId: [{ required: true, message: '请选择产品', trigger: 'blur' }],
        fProductBatchNo: [{ required: true, message: '请选择产品批次', trigger: 'blur' }],
        fTraySpecofocatopns: [{ required: true, message: '请选择托盘规格', trigger: 'blur' }],
        fPayDate: [{ required: true, message: '请选择交付日期', trigger: 'blur' }]
      },
      factoryWhere: { pageNum: 1, pageSize: 20 },
      deviceWhere: { pageNum: 1, pageSize: 20 },
      clientWhere: { pageNum: 1, pageSize: 20 },
      userWhere: { pageNum: 1, pageSize: 20 },
      factoryList: [],
      deviceList: [],
      clientList: [],
      userList: [],
      product: {},
      batchList: [],
      taskSettingKey: 0,
      editForm: {
        fTaskName: '',
        wfOrderTaskEntryList: [],
      }
    }
  },
  methods: {
    handleInput(row) {
      const inputValue = row.fVs;
      if (inputValue >= 0) {
        this.fVs = ''
        row.fVs = null;
      }
    },
    handleInputs(row) {
      const inputValue = row.fVs;
      if (inputValue <= 0) {
        this.fVs = ''
        row.fVs = null;
      }
    },
    handleInputw() {
      const inputValue = this.form.fVcom;
      if (inputValue >= 0) {
        this.form.fVcom = null;
      }
    },
    handleCheckboxChange() {
      if (this.form.fIsMes) {
        this.form.fMesNo = '';
      }
    },
    formatTextNumCollection(row) {
      if (row.fTaskType && row.fTaskType === 1) {
        return '--';
      }
      if (row.fTaskType && row.fTaskType === 2) {
        return '--';
      }
      return row.fTextNumCollection;
    },
    toggleFormVisibility() {
      if (this.form.fVsWSetting) {
        // 关闭时清空表单
        this.wfPlanDetailList = [];
      }
    },
    toggleFormVisibilitys() {
      if (this.form.fVsRSetting) {
        // 关闭时清空表单
        this.wfPlanDetailLists = [];
      }
    },
    /** NA-B 方案管理添加按钮操作 */
    handleAddWfPlanDetail() {
      let obj = {};
      obj.fHeatStage = "";
      obj.fVs = "";
      this.wfPlanDetailList.push(obj);
    },
    /** NA-B 方案管理删除按钮操作 */
    handleDeleteWfPlanDetail(index) {
      this.wfPlanDetailList.splice(index, 1);
    },
    /** 复选框选中数据 */
    handleWfPlanDetailSelectionChange(selection) {
      this.checkedWfPlanDetail = selection.map(item => item.index);
    },
    /** NA-B 方案管理序号 */
    rowWfPlanDetailIndex({ row, rowIndex }) {
      row.index = rowIndex + 1;
    },
    /** NA-B 方案管理添加按钮操作 */
    handleAddWfPlanDetails() {
      let obj = {};
      obj.fHeatStage = "";
      obj.fVs = "";
      this.wfPlanDetailLists.push(obj);
    },
    /** NA-B 方案管理删除按钮操作 */
    handleDeleteWfPlanDetails(index) {
      this.wfPlanDetailLists.splice(index, 1);
    },
    /** 复选框选中数据 */
    handleWfPlanDetailSelectionChanges(selection) {
      this.checkedWfPlanDetails = selection.map(item => item.index);
    },
    openLabs(index) {
      console.log("index", index);
      this.labKey = index
      this.$refs.lab.open()
    },
    handleClick(tab, event) {
      console.log(tab, event);
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.postId)
      this.single = selection.length != 1
      this.multiple = !selection.length
    },
    sureProduct(e) {
      this.form.fProductBatchNo = ''
      this.form.fProductId = e.fId
      this.product = e
      localStorage.setItem('productId', e.fId)
      productNo({ fId: e.fId }).then(res => {
        this.batchList = res.rows
      })
    },
    confirmWave(e) {
      this.dialogWaveVisibles = false;
      this.form.fWaveId = e.fId
      this.form.fWaveName = e.fWaveName
    },
    closeWave() {
      this.dialogWaveVisibles = false;
    },
    openWave() {
      this.dialogWaveVisibles = true
    },
    open() {
      this.show = true
      this.getFactory()
      this.getClient()
      this.getUser()
    },
    getFactory() {
      listOrg(this.factoryWhere).then(res => {
        this.factoryList = [...this.factoryList, ...res.rows]
      })
    },
    changeFactory(e) {
      this.getDevices(e)
      this.form.fDeviceId = ''
    },
    getDevices(fOrgId) {
      this.deviceWhere.fOrgId = fOrgId
      listDevice(this.deviceWhere).then(res => {
        this.deviceList = res.rows
      })
    },
    getDevice() {
      listDevice(this.deviceWhere).then(res => {
        this.deviceList = [...this.deviceList, ...res.rows]
      })
    },
    getClient() {
      listClient(this.clientWhere).then(res => {
        this.clientList = [...this.clientList, ...res.rows]
      })
    },
    getUser() {
      listUser(this.userWhere).then(res => {
        this.userList = [...this.userList, ...res.rows]
      })
    },
    factoryLoad() {
      this.factoryWhere.pageNum += 1
      this.getFactory()
    },
    deviceLoad() {
      this.deviceWhere.pageNum += 1
      this.getDevice()
    },
    clientLoad() {
      this.clientWhere.pageNum += 1
      this.getClient()
    },
    userLoad() {
      this.userWhere.pageNum += 1
      this.getUser()
    },
    closeDialog() {
      this.factoryWhere.pageNum = 1
      this.deviceWhere.pageNum = 1
      this.clientWhere.pageNum = 1
      this.userWhere.pageNum = 1
      this.factoryList = []
      this.deviceList = []
      this.clientList = []
      this.userList = []
    },
    openProduct() {
      this.$refs.product.open()
    },
    sureTaskw(e) {
      this.form.fProductBatchNo = ''
      this.form.fProductId = e.fId
      this.product = e
      localStorage.setItem('productId', e.fId)
      productNo({ fId: e.fId }).then(res => {
        this.batchList = res.rows
      })
    },
    sureTask(e) {
      var value = e.wfOrderTaskEntryList.map((item) => item.fHeatStage);
      var min = Math.min(...value)
      var max = Math.max(...value)
      let data = {
        ...e,
        fHeatStageCollection: min + '-' + max,
        fVsValueCollection: e.wfOrderTaskEntryList.map(item => item.fVsValue).toString(),
        fVcomValueCollection: e.wfOrderTaskEntryList.map(item => item.fVcomValue).toString(),
        fQuietMinuteCollection: e.wfOrderTaskEntryList.reduce((accumulator, currentValue) => accumulator + Number(currentValue.fQuietMinute), 0),
        fTextNumCollection: e.wfOrderTaskEntryList.reduce((accumulator, currentValue) => accumulator + Number(currentValue.fTextNum), 0),

      }
      console.log(this.taskSettingKey);
      if (this.taskSettingKey !== -1) {
        this.$nextTick(() => {
          this.$set(this.form.wfOrderTaskList, this.taskSettingKey, { ...data })
        })
      } else {
        this.form.wfOrderTaskList.push(data)
      }
    },
    surelab(e) {
      console.log(11111, "点击测试");
    },
    showBialog2(i){
      this.taskSettingKey = -1
      this.$refs.boxing.form.fTaskType = i
      this.$refs.boxing.queryParams.fTaskType = i
      this.$refs.boxing.open()
    },
    addSession(i) {
      if (!this.product.fProductName) {
        this.$message({
          message: '请先选择产品',
          type: 'warning'
        })
        return
      }
      this.taskSettingKey = -1
      this.$refs.taskAdds.form.fTaskType = i
      this.$refs.taskAdds.queryParams.fTaskType = i
      this.$refs.taskAdds.open()
    },
    editTask(index) {
      this.taskSettingKey = index
      this.$refs.taskAdds.form.fTaskName = this.form.wfOrderTaskList[index].fTaskName
      this.$refs.taskAdds.form.wfOrderTaskEntryList = [...this.form.wfOrderTaskList[index].wfOrderTaskEntryList]
      this.$refs.taskAdds.open()
      this.$refs.taskAdds.form.check = 0
    },
    showBialog4(index) {
      this.taskSettingKey = index

      this.dialoge2 = true
    },
    delTask(index) {
      this.form.wfOrderTaskList.splice(index, 1)
    },
    toSure() {
      if (this.form.wfOrderTaskList.length < 1) {
        this.$message({
          message: '请添加任务',
          type: 'warning'
        })
        return
      }
      console.log(this.form)
      if (this.wfPlanDetailLists.length > 0) {
        this.wfPlanDetailLists = this.wfPlanDetailLists.map(item => {
          item.fVsType = 1;
          item.fSettingType = 0;
          return item;
        });
      }
      if (this.wfPlanDetailList.length > 0) {
        this.wfPlanDetailList = this.wfPlanDetailList.map(item => {
          item.fVsType = 0;
          item.fSettingType = 0;
          return item;
        });
      }
      if (this.wfPlanDetailList.length > 0 && this.wfPlanDetailLists.length == 0) {
        this.form.wfVsSettingList = this.wfPlanDetailList;
      } else if (this.wfPlanDetailLists.length > 0 && this.wfPlanDetailList.length == 0) {
        this.form.wfVsSettingLists = this.wfPlanDetailLists;
      } else if (this.wfPlanDetailLists.length > 0 && this.wfPlanDetailList.length > 0) {
        this.form.wfVsSettingList = [...this.wfPlanDetailList, ...this.wfPlanDetailLists];
      }
      this.form.fIsMes = this.form.fIsMes ? 1 : 0
      addOrder(this.form).then(res => {
        this.show = false
        this.form = {
          fVsWSetting: 0,
          fVsRSetting: 0,
          fLogicalSettings: 0,
          fOrderNo: '',
          fMesNo: '',
          fIsMes: false,
          fOrderPriority: '',
          fOrderName: '',
          fOrgId: '',
          fDeviceId: '',
          fClientName: '',
          fUserId: '',
          fProductId: '',
          fProductBatchNo: '',
          fTraySpecofocatopns: '',
          fPayDate: '',
          inputs: '',
          fRemark: '',
          fOrderType: 1,
          wfOrderTaskList: [],
          wfPlanDetailList: [],
          wfPlanDetailLists: [],
          wfVsSettingList: []
        }
        this.$message({ message: '提交成功', type: 'success' })
        this.$emit('success')
      })
    },
    refreshPage() {
    }
  }
}
</script>

<style scoped lang="scss">
.even-row {
  background-color: #f5f5f5;
}

.odd-row {
  background-color: #fff;
}

.el-input-div {
  width: 202px;
  height: 36px;
  box-sizing: border-box;
  padding: 0 15px;
  border: 1px solid #DCDFE6;
  border-radius: 4px;
  cursor: pointer;
  white-space: nowrap; // 强制一行显示
  overflow: hidden; // 超出隐藏
  text-overflow: ellipsis; // 省略号
}

.el-dropdown {
  vertical-align: top;
}

.el-dropdown+.el-dropdown {
  margin-left: 15px;
}

.el-icon-arrow-down {
  font-size: 12px;
}
</style>